﻿@model CategoryWrapper
@{
    HierarchicalNodeProviderBase provider = ViewBag.Provider;
    Ajax.Dna().Widget()
        .UserPreferences(@<text>
    @{
        <div>
            Show Columns</div>
        <div style="overflow: hidden;">
            @Ajax.Dna().Number(item.GenerateFieldID("Columns"), item.GetInt("Columns")).GetHtml()
        </div>
        <div>
            Show Depth</div>
        <div style="overflow: hidden;">
            @Ajax.Dna().Number(item.GenerateFieldID("Depth"), item.GetInt("Depth")).GetHtml()
        </div>
        <div style="overflow: hidden;">
            @Ajax.Dna().Checkbox(item.GenerateFieldID("ShowIcons"), "Show icons", (bool)item.GetBool("ShowIcons")).GetHtml()
        </div>
        <span style="clear: left;"></span>
        Ajax.Dna().TreeView(item.GenerateFieldID("TreeView"))
            .HtmlAttributes(new { style = "height:200px;border:1px solid #cccccc;overflow:auto;" })
            .Options(opts =>
            {
                opts.OnNodeSelected = "$(\"#" + item.GenerateFieldID("CategoryID") + "\").val($(node).attr(\"key\"));";
                opts.SinglePathExpand = true;
            })
            .ExpandedLevel(1)
            .SelectNode("key", item.UserPreferences["CategoryID"].ToString())
            .Bind(provider, true)
            .Render();
    }
    <input type="hidden" value="@item.GetInt("CategoryID")" id="@item.GenerateFieldID("CategoryID")" name="@item.GenerateFieldID("CategoryID")" />
    </text>)
        .Preview(widget =>
        {
            Ajax.Dna().SiteMap(widget.GenerateFieldID("PreviewTreeView"))
                .Items(nodes =>
                {
                    nodes.Add("Uncategoried", "#", Url.Content("~/content/images/icon_cat_16.gif")).Items(subnodes =>
                    {
                        subnodes.Add("Category1", "#", Url.Content("~/content/images/icon_cat_16.gif"));
                        subnodes.Add("Category2", "#", Url.Content("~/content/images/icon_cat_16.gif"));
                        subnodes.Add("Category3", "#", Url.Content("~/content/images/icon_cat_16.gif"));
                        subnodes.Add("Category4", "#", Url.Content("~/content/images/icon_cat_16.gif"));
                    });
                })
                .Render();
        })
        .Content(@<text>
    @if ((Model != null) && ((IHierarchyData)Model).HasChildren)
    {

        Ajax.Dna().SiteMap()
            .Columns(item.GetInt("Columns"))
            .Levels(item.GetInt("Depth") > 1 ? (item.GetInt("Depth") - 1) : 1)
            .Name(item.GenerateFieldID("cat_map"))
            .Bind<CategoryWrapper>((IHierarchicalEnumerable)Model, (cat, node) =>
            {
                node.Text = cat.Title + " (" + cat.TotalPosts.ToString() + ")";
                node.NavigateUrl = cat.PermaLink.ToString();
                if (item.GetBool("ShowIcons"))
                    node.ImageUrl = Url.Content("~/content/images/icon_cat_16.gif");
                node.ToolTip = cat.Description;
                return true;
            })
            .Render();
    }
    else
    {
        <div style="padding: 10px;">
            @Html.Global("publishing", "NoCategories")</div>
    }
    </text>)
        .Render();
}
